<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>选择票券</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
    <style type="text/css">
        .index-outside > section .section-main {
            min-width: 0px !important;
            max-width: 800px !important;
        }

        .index-outside > section {
            padding-bottom: 0px !important;
        }
    </style>
</head>
<body>
<!--头部-->
<div class="index-outside">
    <!--内容-->
    <section class="no-fix">
        <div class="section-main" style="padding: 15px;">
            <form class="layui-form" action="${ctx}/coupon/coupon/selectCoupon.do" id="myForm"
                  method="post">
                <input type="hidden" name="pageNo" id="pageNo" value="${page.page}"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">票券名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" autocomplete="off" class="layui-input"
                                           value="${coupon.name}" placeholder="请输入查询票券名称" style="width: 200px;">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger" id="submitBtn">确定</a>
                                    <a class="layui-btn layui-btn-normal" id="resetBtn">重置</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="c-time-list-content" style="padding-top: 0px;">
                <input type="hidden" id="couponId"/>
                <input type="hidden" id="couponName"/>
                <input type="hidden" id="stock"/>
                <ul>
                    <table class="layui-table layui-form">
                        <colgroup>
                            <col width="100px">
                            <col>
                            <col width="120px">
                            <col width="120px">
                        </colgroup>
                        <thead>
                        <tr>
                            <th></th>
                            <th>票券名称</th>
                            <th>库存数量</th>
                            <th>剩余数量</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="cc" items="${coupons}">
                            <tr>
                                <td><input type="radio" name="id" value="${cc.id}" lay-filter="coupon" title="&nbsp;">
                                </td>
                                <td class="ellipsis-1 coupon-name" data-name="${cc.name}">${cc.name}</td>
                                <td>${cc.stock}</td>
                                <td>
                                    <c:set var="notAllotNum" value=""/>
                                    <c:if test="${selectCoupon.couponId == cc.id}">
                                        <c:set var="notAllotNum" value="${cc.allotNum + selectCoupon.allotNum}"/>
                                    </c:if>
                                    <c:if test="${selectCoupon.couponId != cc.id}">
                                        <c:set var="notAllotNum" value="${cc.allotNum}"/>
                                    </c:if>
                                    <input type="hidden" class="coupon-stock" value="${notAllotNum}"/>
                                    ${notAllotNum}
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </ul>
            </div>
            <div id="page_content" class="page-container"></div>
        </div>
    </section>
</div>
<!--底部-->
<%@include file="../include/incScript.jsp" %>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">
    $(function () {
        // 加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        layui.use(['form', 'laypage'], function () {
            var form = layui.form;

            form.on('radio(coupon)', function (data) {
                var $tr = $(data.elem).closest("tr");
                $("#couponId").val(data.value);
                $("#couponName").val($tr.find(".coupon-name").data("name"));
                $("#stock").val($tr.find(".coupon-stock").val());
            });
        });
        $("#submitBtn").click(function () {
            $("#myForm").submit();
        });

        $("#resetBtn").click(function () {
            $("#myForm input[type=text]").val("");
        });
    });

    function doSubmit() {
        var couponId = $("#couponId").val();
        var stock = $("#stock").val();
        if (couponId == "") {
            util.layerMsgError("请先选择票券")
            return false;
        }
        if (stock == "0") {
            util.layerMsgError("请先选择库存大于0的票券")
            return false;
        }
        return true;
    }
</script>
</body>
</html>